package org.cy.websocket.stomp.messaging;

import java.nio.charset.StandardCharsets;

/**
 * Created in 2021-05-10 23:21
 *
 * @author cao.yong
 */
public class StringMessageConverter {

    public static String fromMessage(Message<byte[]> message) {
        return new String(message.getPayload(), StandardCharsets.UTF_8);
    }

    public static Message<byte[]> toMessage(Message<?> message, String payload) {
        return new GenericMessage<>(message.getCommand(), message.getHeaders(), payload.getBytes(StandardCharsets.UTF_8));
    }
}
